/*
 * FileReader.h
 *
 *  Created on: Aug 31, 2013
 *      Author: Jeff
 */

#ifndef FILEREADER_H_
#define FILEREADER_H_

#include <json/json.h>

#include <fstream>
#include <iostream>

#include "IFileReader.h"

namespace fs {

class FileReader : public IFileReader {
private:
	Json::Value info;
	Json::Value segments;

	unsigned int currentSegment;
	int offset;
	int delete_length;
	int insert_length;

	IFileReader* fs_base;
	std::fstream fs_diff;
	std::filebuf *cursor_diff;

	bool loadSegment();
	bool endOfSegment();

	void init(Json::Value json);
	bool readJsonFromFile(const char* file, Json::Value* json);

public:
	FileReader(Json::Value info);
	FileReader(const char* file);
	virtual ~FileReader();

	int read(char* buffer, int len);
	int skip(int len);
};

} /* namespace fs */
#endif /* FILEREADER_H_ */
